// To parse this JSON data, do
//
//     final commentDetailModel = commentDetailModelFromJson(jsonString);

import 'dart:convert';

CommentDetailModel commentDetailModelFromJson(String str) => CommentDetailModel.fromJson(json.decode(str));

String commentDetailModelToJson(CommentDetailModel data) => json.encode(data.toJson());

class  CommentListModel {
  List<CommentDetailModel> list;
   CommentListModel(this.list);

  factory  CommentListModel.fromJson(List<dynamic> list) {
    // 调用自身构造方法传值并返回
    return  CommentListModel(
      list.map((listItem) => CommentDetailModel.fromJson(listItem)).toList(),
    );
  }
}


class CommentDetailModel {
    CommentDetailModel({
        this.id,
        this.userId,
        this.momentId,
        this.content,
        this.parentId,
        this.replyToId,
        this.likeCount,
        this.status,
        this.artistId,
        this.ipAddress,
        this.ipSource,
        this.createTime,
        this.updateTime,
        this.userName,
        this.userAvatarUrl,
        this.hasLiked,
        this.hasFollowed,
        this.replyCount,
        this.replyToComment,
        this.parentCommentContent,
    });

    int id;
    int userId;
    int momentId;
    String content;
    int parentId;
    int replyToId;
    int likeCount;
    int status;
    int artistId;
    String ipAddress;
    String ipSource;
    DateTime createTime;
    DateTime updateTime;
    String userName;
    String userAvatarUrl;
    bool hasLiked;
    bool hasFollowed;
    int replyCount;
    String parentCommentContent;
    CommentDetailModel replyToComment;

    factory CommentDetailModel.fromJson(Map<String, dynamic> json) => CommentDetailModel(
        id: json["id"],
        userId: json["userId"],
        momentId: json["momentId"],
        content: json["content"],
        parentId: json["parentId"],
        replyToId: json["replyToId"],
        likeCount: json["likeCount"],
        status: json["status"],
        artistId: json["artistId"],
        ipAddress: json["ipAddress"],
        ipSource: json["ipSource"],
        createTime: DateTime.parse(json["createTime"]),
        updateTime: DateTime.parse(json["updateTime"]),
        userName: json["userName"],
        userAvatarUrl: json["userAvatarUrl"],
        hasLiked: json["hasLiked"],
        hasFollowed: json["hasFollowed"],
        replyCount: json["replyCount"],
        parentCommentContent:json["parentCommentContent"]!=null? json["parentCommentContent"]:null,
          replyToComment: json["replyToComment"] == null
            ? null
            : CommentDetailModel.fromJson(json["replyToComment"]),
    );

    Map<String, dynamic> toJson() => {
        "id": id,
        "userId": userId,
        "momentId": momentId,
        "content": content,
        "parentId": parentId,
        "replyToId": replyToId,
        "likeCount": likeCount,
        "status": status,
        "artistId": artistId,
        "ipAddress": ipAddress,
        "ipSource": ipSource,
        "createTime": createTime.toIso8601String(),
        "updateTime": updateTime.toIso8601String(),
        "userName": userName,
        "userAvatarUrl": userAvatarUrl,
        "hasLiked": hasLiked,
        "hasFollowed": hasFollowed,
        "replyCount": replyCount,
        "  parentCommentContent":  parentCommentContent == null ? null : parentCommentContent,
          "repostedMoment":
            replyToComment == null ? null : replyToComment.toJson(),
    };
}
